using Microsoft.EntityFrameworkCore;
using Admin3000.Backend.Api.Entity;

namespace Admin3000.Backend.Api.Database
{
    /// <summary>
    /// 数据库上下文，这里定义这些实体对应的数据表、及连接参数
    /// </summary>
    public class Admin3000Db : DbContext
    {
        /// <summary>
        /// 采用依赖注入的方式的时，必须提供其构造函数，并且调用其父类构造函数
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public Admin3000Db(DbContextOptions options) : base(options)
        {

        }
        public DbSet<Users> Users { get; set; }
        public DbSet<Roles> Roles { get; set; }
        public DbSet<UserRoles> UserRoles { get; set; }
        public DbSet<AuditInfo> AuditInfo { get; set; }
        public DbSet<Admin> Admin { get; set; }
        public DbSet<Arcitle> Arcitle { get; set; }
        public DbSet<articleType> articleType { get; set; }
        public DbSet<Comment> Comment { get; set; }
        public DbSet<Information> Information { get; set; }
        public DbSet<QRcode> QRcode { get; set; }
        public DbSet<Rotation> Rotation { get; set; }
        public DbSet<PictureInfo> pictureInfos {get;set;}
        public DbSet<Slideshow> Slideshow {get;set;}

        // protected override void OnConfiguring(DbContextOptionsBuilder options)
        // {
        //     options.UseSqlServer(@"server=.;database=Admin3000;uid=sa;pwd=113;");
        // }

        protected override void OnModelCreating(ModelBuilder modelBuilder){
            // 初始化一个管理员用户 虽然Id是自动生成，但此处必须明确指定
            modelBuilder.Entity<Users>().HasData(
                new Users{
                    Id=1,
                    Username="admin",
                    Password="113",
                    IsActived=true,
                    IsDeleted=false,
                    CreatedTime=System.DateTime.Now,
                    UpdatedTime=System.DateTime.Now,
                    DisplayOrder=0,
                    Remarks=null
                }       
            );
            base.OnModelCreating(modelBuilder);
        }
    }
}